package com.eden.manage.controller;

import com.eden.manage.dto.PageComDto;
import com.eden.manage.dto.agent.AgentDto;
import com.eden.manage.req.query.AgentQuery;
import com.eden.manage.service.AgentService;
import eden.api.common.model.EdenPageResult;
import eden.api.common.model.EdenResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("agent")
@RequiredArgsConstructor
public class AgentController {

    private final AgentService agentService;

    @PostMapping("index")
    public EdenPageResult<?> pageList(@RequestBody AgentQuery agentQuery){
        PageComDto<AgentDto> pageDto = agentService.pageList(agentQuery);
        return EdenPageResult.ok(pageDto.getList(), pageDto.getCount());
    }


    @PostMapping("")
    public EdenResult<?> edit(@RequestBody AgentDto agentDto){
        agentService.editAgent(agentDto);
        return EdenResult.ok("");
    }

    @PatchMapping("open/{id}")
    public EdenResult<?> openAgent(@PathVariable("id") Long id){
        agentService.openAgent(id);
        return EdenResult.ok("");
    }

    @PatchMapping("frozen/{id}")
    public EdenResult<?> frozenAgent(@PathVariable("id") Long id){
        agentService.frozenAgent(id);
        return EdenResult.ok("");
    }
    @PatchMapping("free/{id}")
    public EdenResult<?> freeAgent(@PathVariable("id") Long id){
        agentService.freeAgent(id);
        return EdenResult.ok("");
    }
}
